<template>
  <!-- 非车保险-->
  <view class="normal-login-container">

    <view class="item-wrap" style="margin-bottom: 0">
      <view class="lineBottom10 title-uni-in">
        <uni-section title="投保要求" type="line"/>
      </view>
      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
        <uni-forms ref="ruleForm" :model="ruleForm" :label-position="boole ? 'top' : 'left'" labelWidth="auto">

          <uni-forms-item label="禀议内供应商:">
            <uni-easyinput v-if="boole" v-model="ruleForm.rentInsuranceCompany" disabled
                           placeholder="请输入禀议内供应商"/>
            <text v-else> {{ ruleForm.rentInsuranceCompany || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="投保渠道:">
            <zxz-uni-data-select v-if="boole" v-model="ruleForm.insuranceChannels.toString()"
                                 :localdata="insuranceList" dataKey="label" dataValue="value"
                                 disabled/>
            <text v-else> {{ handleLabel(insuranceList, ruleForm.insuranceChannels) }}
            </text>
          </uni-forms-item>

          <uni-forms-item label="被保险人:" name="syxInsuredName" :required="boole"
                          :rules="[{required:true, errorMessage: '请输入被保险人',validateTrigger:'blur'}]">
            <text class="syxInsuredName"/>
            <uni-easyinput v-if="boole" v-model="ruleForm.syxInsuredName" placeholder="请输入被保险人"/>
            <text v-else> {{ ruleForm.syxInsuredName || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="保险起期:" name="syxExpectBeginTime" :required="boole"
                          :rules="[{required:true, errorMessage: '请选择保险起期',validateTrigger:'bind'}]">
            <text class="syxExpectBeginTime"/>
            <uni-datetime-picker v-if="boole" type="date" placeholder="请选择保险起期" return-type="string"
                                 v-model="ruleForm.syxExpectBeginTime"/>
            <text v-else> {{ ruleForm.syxExpectBeginTime || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="保险性质:" name="syxInsuranceType" :required="boole"
                          :rules="[{required:true, errorMessage: '请选择保险性质',validateTrigger:'bind'}]">
            <text class="syxInsuranceType"/>
            <uni-data-select v-if="boole" v-model="ruleForm.syxInsuranceType" :localdata="range"
                             placeholder="请选择保险性质" :clear="true" filterable/>
            <text v-else> {{
                ruleForm.syxInsuranceType == '1' ? '运营' : ruleForm.syxInsuranceType == '2' ? '非运营' : ''
              }}
            </text>
          </uni-forms-item>

          <uni-forms-item label="特殊事项说明:">
            <uni-easyinput type="textarea" v-if="boole" v-model="ruleForm.syxRemark"
                           placeholder="请输入特殊事项说明"/>
            <text v-else>{{ ruleForm.syxRemark || '-' }}</text>
          </uni-forms-item>

        </uni-forms>
      </view>
    </view>
  </view>
</template>

<script>
export default  {
  name: 'divisionPurchase',//投保要求
  components: {},
  props: {
    value: {
      type: Object,
      default: {},
    },
    boole: {
      type: Boolean,
      default: true,
    },
    insuranceList:{
      type: Array,
      default: [],
    }
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.handleData(key, value)
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    handleLabel() {
      return function (arr, type) {
        let name = "";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },
  },
  data() {
    return {
      range: [
        {value: "1", text: "运营"},
        {value: "2", text: "非运营"},
      ],
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleData(key, value) {
      if ([1, 2].includes(Number(this.value.insuranceChannels))
          || this.value.insuranceVoList.length === 1) {
        this.value.insuranceVoList.forEach(item => {
          if (typeof (item) !== "string") {
            item[key] = value
          } else {
            item[key] = value
          }

        })
      }
    },

    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate().then((res) => {
          resolve();
        }).catch((err) => {
          let key = ".flex-col" + ">>>" + "." + err[0].key;
          reject(key);
        });
      });
    },
  },
};
</script>

<style scoped lang="scss">
.title-uni-in {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
</style>


